import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
// import store from '@/store'
import LoginLo from '@/views/LoginLo'
import HomePage from '@/views/HomePage'
import LayoutLa from '@/views/LayoutLa'
import ExperienceProject from '@/views/ExperienceProject'
import BusiNess from '@/views/BusiNess'
Vue.use(VueRouter)

// const routes = [

// ]

const router = new VueRouter({
  routes: [
    { path: '/loginlo', component: LoginLo },
    { path: '/experienceproject', component: ExperienceProject },
    {
      path: '/LayoutLa',
      component: LayoutLa,
      redirect: '/homepage',
      children: [{ path: '/homepage', component: HomePage },
        { path: '/business', component: BusiNess }
      ]
    }
  ]
})

export default router
// 登录访问拦截
router.beforeEach((to, from, next) => {
  const { token } = store.state.user
  if (to.path !== '/login' && !token) return next('/login')
  next()
})
